package show.me.the.money.util.context;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;

import show.me.the.money.util.T;


public class DateContext extends Context {

	public Object get(String name, HashMap<String, Object> arg) {
		GregorianCalendar cdr = new GregorianCalendar();
		if (name.equals("date")) {
			return T.formatDate(cdr.getTime());
		}
		if (name.equals("datetime")) {
			return T.formatDateTime(cdr.getTime());
		}
		if (name.equals("time")) {
			return T.formatTime(cdr.getTime());
		}
		if (name.equals("dateOfPreDay")) {
			cdr.add(Calendar.DAY_OF_MONTH, -1);
			return T.formatDate(cdr.getTime());
		}

		if (name.equals("dateOfPreMonth")) {
			cdr.add(Calendar.MONTH, -1);
			return T.formatDate(cdr.getTime());
		}
		if (name.equals("dateOfPreYear")) {
			cdr.add(Calendar.YEAR, -1);
			return T.formatDate(cdr.getTime());
		}
		if (name.equals("dateOfNextDay")) {
			cdr.add(Calendar.DAY_OF_MONTH, 1);
			return T.formatDate(cdr.getTime());
		}
		if (name.equals("dateOfNextMonth")) {
			cdr.add(Calendar.MONTH, 1);
			return T.formatDate(cdr.getTime());
		}
		if (name.equals("dateOfNextYear")) {
			cdr.add(Calendar.YEAR, 1);
			return T.formatDate(cdr.getTime());
		}
		if (name.equals("year")) {
			return String.valueOf(cdr.get(Calendar.YEAR));
		}
		if (name.equals("preYear")) {
			cdr.add(Calendar.YEAR, -1);
			return String.valueOf(cdr.get(Calendar.YEAR));
		}
		if (name.equals("nextYear")) {
			cdr.add(Calendar.YEAR, 1);
			return String.valueOf(cdr.get(Calendar.YEAR));
		}
		if (name.equals("month")) {
			return String.valueOf(cdr.get(Calendar.MONTH) + 1);
		}
		if (name.equals("monthFirstDay")) {
			int day = cdr.get(Calendar.DAY_OF_MONTH);
			cdr.add(Calendar.DAY_OF_MONTH, -day + 1);
			return T.formatDate(cdr.getTime());
		}
		if (name.equals("preMonth")) {
			cdr.add(Calendar.MONTH, -1);
			return String.valueOf(cdr.get(Calendar.MONTH));
		}
		if (name.equals("nextMonth")) {
			cdr.add(Calendar.MONTH, 1);
			return String.valueOf(cdr.get(Calendar.MONTH));
		}
		if (name.equals("timeToLong")) {
			return cdr.getTimeInMillis();
		}
		return "";

	}

}
